package run.jingjing.websocket.model;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: jingjing
 * @date: 2021/6/24
 * @description:
 */
public class LWsGroup extends ConcurrentHashMap<String, LWsTopic> {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public LWsTopic get(Object key) {
        String topicName = (String) key;
        LWsTopic topic = super.get(topicName);
        if (topic == null) {
            synchronized (this.getClass()) {
                topic = super.get(key);
                if (topic == null) {
                    LWsTopic lWsTopic = new LWsTopic();
                    lWsTopic.setName(topicName);
                    lWsTopic.setlWsGroup(this);
                    topic = lWsTopic;
                    super.put(topicName,lWsTopic);
                }
            }
        }
        return topic;
    }
}
